import { Refund } from 'refund-model.js';
var refund = new Refund();
Page({

  data: {
    process1: [
      {name:'提交申请'},
      {name:'用户发货'},
      {name:'卖家收货并退款'},
      {name:'完成'}
    ],
    process2: [
      { name: '提交申请' },
      { name: '用户发货' },
      { name: '卖家进行换货'},
      { name: '完成'}
    ],
    process :[],
    status : 1,  //1已提交申请，2用户已发货，3卖家已收货/完成
  },
  onLoad: function (options) {
    var type = options.type;
    var id = options.id;
    if(!type || !id){
      return false;
    }
    if(type == 1){
      var text = "退款退货流程"
      var process = this.data.process1
    } else if (type == 2) {
      var text = "换货流程"
      var process = this.data.process2
    }
    this.setData({
      type,
      id,
      process,
      text
    })
    
    this._loadData();
  },
  //获取详情
  _loadData: function () {
    wx.showLoading({
      title: '加载中',
    })
    var that = this;
    var args = {
      id: this.data.id
    }
    refund.info(args, (res) => {
      wx.hideLoading();
      var data = res.item;
      that.setData({
        info: data,
      })
      if (data.receive_status == 1){
        var status = 4;
        var pText = "本次售后已完成";
      } else if (data.receive_status == 0 && data.delivery_no){
        var status = 2;
        var pText = "请等待卖家接收邮寄的商品";
      }
      else if (data.receive_status == 0 && !data.delivery_no) {
        var status = 1;
        var pText = "请在底部联系客服，并将商品邮寄给卖家";
      }
      var p = that.data.process;
      p.forEach((item, index) => {
        if (index < status){
          p[index].checked = true
        }
      })
      that.setData({
        process : p,
        pText,
        status
      })
    });
  },
  //跳转到填写发货单页面
  gotoFahuoNum: function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: './fahuo-num?id=' + id
    })
  },
  toJinduList:function(){
    wx.navigateTo({
      url: './jindu-list',
    })
  },
  toComRecord:function(){
    wx.navigateTo({
      url: './communication-record',
    })
  },
})